//
//  ZJOriginalView.swift
//  Webo
//
//  Created by 曾静 on 16/6/27.
//  Copyright © 2016年 qq. All rights reserved.
//

import UIKit

import SnapKit

class ZJOriginalView: UIView {

    private var orginalViewBottonContrast:Constraint?
    
    var status:ZJStatues?{
        
        didSet{
            
            //设置原创微博的数据信息
            //头像
            headView.sd_setImageWithURL(NSURL(string: (status?.user?.profile_image_url ?? "")), placeholderImage: UIImage(named: "avatar_default_big"))
            //昵称
            nameLabel.text = status?.user?.name
            
            textLab.text = status?.text
            
            //认证的等级信息
            vipImageView.image = status?.user?.verifiedImage

            //vip的等级信息
            classImageView.image = status?.user?.mbrankImage
            
             scourceLabel.attributedText = status?.sourceAttr
            
            timeLabel.text = status?.creatString
            
           orginalViewBottonContrast?.uninstall()
           //对pictureView的有无进行判断
            if status?.pic_urls?.count > 0 {
                
                //显示视图
                pictureView1.hidden = false
                //赋值
                pictureView1.status = status
                //更新约束
                self.snp_updateConstraints { (make) -> Void in
                    
                    orginalViewBottonContrast = make.bottom.equalTo(pictureView1).offset(OriginalMargin).constraint
                }
                
            }else{
                //隐藏视图
                pictureView1.hidden = true

                //更新约束
                self.snp_updateConstraints { (make) -> Void in
                    
                     orginalViewBottonContrast = make.bottom.equalTo(textLab).offset(OriginalMargin).constraint
                }

            }
            
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
   
        
        backgroundColor = UIColor.whiteColor()
        //添加控件
        addSubview(headView)
        addSubview(nameLabel)
        addSubview(classImageView)
        addSubview(timeLabel)
        addSubview(scourceLabel)
        addSubview(vipImageView)
        addSubview(textLab)
        addSubview(pictureView1)
        
        headView.snp_makeConstraints { (make) -> Void in
            
            make.top.leading.equalTo(self).offset(OriginalMargin)
            
            make.size.equalTo(CGSize(width: 35, height: 35))
        }
        
        nameLabel.snp_makeConstraints { (make) -> Void in
            
            make.leading.equalTo(headView.snp_trailing).offset(OriginalMargin)
            
            make.top.equalTo(headView)
            
        }
        
        timeLabel.snp_makeConstraints { (make) -> Void in
            
            make.leading.equalTo(nameLabel)
            
            make.bottom.equalTo(headView)
        }
        
        
        
        classImageView.snp_makeConstraints { (make) -> Void in
            
            make.centerY.equalTo(nameLabel)
            
            make.leading.equalTo(nameLabel.snp_trailing).offset(OriginalMargin)
            
            
        }
        
        
        scourceLabel.snp_makeConstraints { (make) -> Void in
            
            make.bottom.equalTo(timeLabel)
            
            make.leading.equalTo(timeLabel.snp_trailing).offset(OriginalMargin)
        }
        
        vipImageView.snp_makeConstraints { (make) -> Void in
            
            
            make.centerY.equalTo(headView.snp_bottom)
            
            make.centerX.equalTo(headView.snp_trailing)
        }
        
        textLab.snp_makeConstraints { (make) -> Void in
            
            make.leading.equalTo(self).offset(OriginalMargin)
            
            make.top.equalTo(headView.snp_bottom).offset(OriginalMargin)
               
        }
        
        pictureView1.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(textLab)
            make.top.equalTo(textLab.snp_bottom).offset(OriginalMargin)
            
        }
        
        
        
        self.snp_makeConstraints { (make) -> Void in
            
           orginalViewBottonContrast = make.bottom.equalTo(pictureView1).offset(OriginalMargin).constraint
        }
        
        timeLabel.text = "时间"
       
        nameLabel.text = "小话唠"
        
        textLab.text = "哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈"
        
    }
   
    private lazy var headView:UIImageView = UIImageView(imageName: "avatar_default_big")
    private lazy var nameLabel:UILabel = UILabel(textColor: UIColor.darkGrayColor(), textSize: 15)
    
    private lazy var classImageView:UIImageView = UIImageView(imageName: "common_icon_membership_expired")
    
    private lazy var timeLabel:UILabel = UILabel(textColor: ThemeColor, textSize: 10)
    private lazy var scourceLabel:UILabel = UILabel(textColor: UIColor.grayColor(), textSize: 10)
    private lazy var vipImageView:UIImageView = UIImageView(imageName: "avatar_vgirl")
    
    private lazy var textLab:UILabel = UILabel(textColor: UIColor.blackColor(), textSize: 15, maxWidth: SCREENW - 2*OriginalMargin)
    
    private lazy var pictureView1:ZJPictureView = ZJPictureView()
}
